// var o;
// exports.WorldRankConfig = void 0;
// var AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");
// var c = (function (e) {
//     function t() {
//         return (null !== e && e.apply(this, arguments)) || this;
//     }
//     __extends(t, e);
//     t.getInstance = function () {
//         return this.instance || (this.instance = new t());
//     };
//     t.prototype.destroy = function () {
//         t.instance = null;
//     };
//     t.prototype.jiazai_peizhi = function () {
//         return __awaiter(this, void 0, void 0, function () {
//             var e;
//             var t;
//             var n;
//             return __generator(this, function (o) {
//                 switch (o.label) {
//                     case 0:
//                         return [4, this.yibu_jiazai_txt_peizhi("WorldRank")];
//                     case 1:
//                         if ((e = o.sent())) {
//                             this.weeklyRewards = [];
//                             this.dailyRewards = [];
//                             t = e.daily;
//                             n = e.weekly;
//                             t.forEach(function (e) {
//                                 var t = e.rewardType;
//                                 var n = [];
//                                 for (var o = 0; o < t.length; o += 2) {
//                                     var i = t[o];
//                                     var r = t[o + 1];
//                                     n.push({
//                                         goodsId: i,
//                                         num: r
//                                     });
//                                 }
//                                 e.rewardType = n;
//                             });
//                             n.forEach(function (e) {
//                                 var t = e.rewardType;
//                                 var n = [];
//                                 for (var o = 0; o < t.length; o += 2) {
//                                     var i = t[o];
//                                     var r = t[o + 1];
//                                     n.push({
//                                         goodsId: i,
//                                         num: r
//                                     });
//                                 }
//                                 e.rewardType = n;
//                             });
//                             this.weeklyRewards = n;
//                             this.dailyRewards = t;
//                         }
//                         return [2];
//                 }
//             });
//         });
//     };
//     t.prototype.huoqu_meizhou_jianli_genju_mingci = function (e) {
//         if (!e) {
//             return null;
//         }
//         for (var t = 0; t < this.weeklyRewards.length; t++) {
//             var n = this.weeklyRewards[t];
//             if (e >= n.rankStart && e <= n.rankEnd) {
//                 return n;
//             }
//         }
//         return null;
//     };
//     t.prototype.huoqu_meiri_jianli_genju_mingci = function (e) {
//         for (var t = 0; t < this.dailyRewards.length; t++) {
//             var n = this.dailyRewards[t];
//             if (e >= n.rankStart && e <= n.rankEnd) {
//                 return n;
//             }
//         }
//         return null;
//     };
//     t.prototype.huoqu_dangtian_paiming_shengyu_shijian = function () {
//         var e = AL_GAME_HUA_Common.Common.huoqu_dangqian_shijian();
//         var t = new Date(e);
//         t.setHours(0, 0, 0, 0);
//         return t.getTime() + 864e5 - e;
//     };
//     t.prototype.huoqu_zhou_paiming_shengyu_shijian = function () {
//         var e = AL_GAME_HUA_Common.Common.huoqu_dangqian_shijian();
//         var t = new Date(e);
//         var n = t.getDay();
//         var o = 0;
//         if (0 !== n) {
//             o = 7 - n;
//         }
//         t.setDate(t.getDate() + o);
//         t.setHours(24, 0, 0, 0);
//         return t.getTime() - e;
//     };
//     t.instance = null;
//     return t;
// })(require("./AL_GAME_HUA_ConfigHandler").ConfigHandler);
// exports.WorldRankConfig = c;


// 引入必要的外部模块
exports.WorldRankConfig = void 0;
const AL_GAME_HUA_Common = require("./AL_GAME_HUA_Common");

// 定义一个类 c 实现单例模式，用于管理世界排名配置
class c extends require("./AL_GAME_HUA_ConfigHandler").ConfigHandler {
    static instance = null;
    
    // 获取实例的方法，确保只有一个实例（单例模式）
    static getInstance() {
        return this.instance || (this.instance = new c());
    }

    // 销毁实例的方法，将实例置为空
    destroy() {
        c.instance = null;
    }

    // 异步加载配置的方法
    async jiazai_peizhi() {
        const config = await this.yibu_jiazai_txt_peizhi("WorldRank");
        
        if (config) {
            this.weeklyRewards = [];
            this.dailyRewards = [];
            const { daily, weekly } = config;

            // 重构每日及每周奖励数据结构
            daily.forEach(rank => {
                rank.rewardType = this.structure_Reward(rank.rewardType);
            });

            weekly.forEach(rank => {
                rank.rewardType = this.structure_Reward(rank.rewardType);
            });

            this.weeklyRewards = weekly;
            this.dailyRewards = daily;
        }
    }

    // 根据名次获取每周奖励
    huoqu_meizhou_jianli_genju_mingci(rank) {
        if (!rank) {
            return null;
        }
        
        for (const reward of this.weeklyRewards) {
            if (rank >= reward.rankStart && rank <= reward.rankEnd) {
                return reward;
            }
        }
        return null;
    }

    // 根据名次获取每日奖励
    huoqu_meiri_jianli_genju_mingci(rank) {
        for (const reward of this.dailyRewards) {
            if (rank >= reward.rankStart && rank <= reward.rankEnd) {
                return reward;
            }
        }
        return null;
    }

    // 获取当天排名剩余时间的毫秒数
    huoqu_dangtian_paiming_shengyu_shijian() {
        const currentTime = AL_GAME_HUA_Common.Common.huoqu_dangqian_shijian();
        const today = new Date(currentTime);
        today.setHours(0, 0, 0, 0);
        return today.getTime() + 86400000 - currentTime;
    }

    // 获取周排名剩余时间的毫秒数
    huoqu_zhou_paiming_shengyu_shijian() {
        const currentTime = AL_GAME_HUA_Common.Common.huoqu_dangqian_shijian();
        const today = new Date(currentTime);
        const dayOfWeek = today.getDay();
        let remainingDays = 0;
        
        if (dayOfWeek !== 0) {
            remainingDays = 7 - dayOfWeek;
        }
        
        today.setDate(today.getDate() + remainingDays);
        today.setHours(24, 0, 0, 0);
        
        return today.getTime() - currentTime;
    }

    // 将原始奖励数组转换为结构化数组的助手函数
    structure_Reward(rewardArray) {
        const rewards = [];
        
        for (let i = 0; i < rewardArray.length; i += 2) {
            const goodsId = rewardArray[i];
            const amount = rewardArray[i + 1];
            rewards.push({ goodsId, num: amount });
        }
        
        return rewards;
    }
}

// 输出类 c
exports.WorldRankConfig = c;